/**
 * Project Name:renshuaipeng-parent
 * File Name:BeetlConfig
 * Package Name:ren.renshuaipeng.search.conf
 * Date:15-12-13
 * Copyright (c) 2015, niao.shuai123@163.com All Rights Reserved.
 */

package ren.renshuaipeng.util.search.conf;

import org.beetl.core.resource.ClasspathResourceLoader;
import org.beetl.ext.spring.BeetlGroupUtilConfiguration;
import org.beetl.ext.spring.BeetlSpringViewResolver;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.io.IOException;

/**
 * ClassName:BtlConfig <br/>
 * Function: btl 配置文件. <br/>
 * Date:     15-12-13 <br/>  
 * @author 任帅鹏（作者）
 * @version V1.00 （版本号）  
 * @since JDK 1.8  
 * @see
 */
@Configuration
public class BtlConf {

    private static final Logger logger = LoggerFactory
            .getLogger(BtlConf.class);

    @Bean(initMethod = "init", name = "btlGroupUtilConfiguration")
    public BeetlGroupUtilConfiguration getBtlGroupUtilConfiguration() throws IOException{

        BeetlGroupUtilConfiguration beetlGroupUtilConfiguration = new BeetlGroupUtilConfiguration();

        ClasspathResourceLoader classpathResourceLoader=new ClasspathResourceLoader("/templates");
        beetlGroupUtilConfiguration.setResourceLoader(classpathResourceLoader);
        //读取配置文件信息
        logger.debug("BtlConfig 配置城管给");
        return beetlGroupUtilConfiguration;
    }

    @Bean(name = "btlViewResolver")
    public BeetlSpringViewResolver getBtlSpringViewResolver(@Value("${spring.mvc.view.prefix}") String prefix,
                                                            @Value("${spring.mvc.view.suffix}") String suffix,
            @Qualifier("btlGroupUtilConfiguration") BeetlGroupUtilConfiguration beetlGroupUtilConfiguration) {
        BeetlSpringViewResolver beetlSpringViewResolver = new BeetlSpringViewResolver();
        beetlSpringViewResolver.setPrefix(prefix);
        beetlSpringViewResolver.setSuffix(suffix);
        beetlSpringViewResolver.setContentType("text/html;charset=UTF-8");
//        beetlSpringViewResolver.setOrder(0);
        beetlSpringViewResolver.setConfig(beetlGroupUtilConfiguration);
        return beetlSpringViewResolver;
    }
}
